// 食物记录的次数
const { DataTypes } = require("sequelize");
const sequelize = require("../config/sequelize");
const User = require("./user");
const Food = require("./food");

const FoodUseNum = sequelize.define(
  "FoodUseNum",
  {
    num: {
      type: DataTypes.INTEGER,
      defaultValue: 0,
      comment: "食物被记录次数",
    },
  },
  {
    sequelize: sequelize,
    tableName: "foodUseNum",
    underscored: true, //显示在数据库字段为下划线
    paranoid: true, // 软删除，调用destroy不会删除模型，而是设置deletedAt时间戳
  }
);



FoodUseNum.belongsTo(Food, {
  constraints: false,
  foreignKey: "foodId",
  as: "food",
});
FoodUseNum.belongsTo(User, {
  constraints: false,
  foreignKey: "userId",
  as: "user",
});

module.exports = FoodUseNum;
